﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;
using ClassLibrary.Entity;
using ClassLibrary.Utilities;

public partial class UserControl_ucRegister : System.Web.UI.UserControl
{
    TblCustomersDAO userDAO = new TblCustomersDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public bool UserAccount_CheckExit()
    {
        bool flag = false;
        try
        {
            flag = userDAO.CheckExits(txtEmail.Text, 1);
        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect("~/Error.aspx", true);
        }
        return flag;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        bool flag = false;
        if (UserAccount_CheckExit())
        {
            lblMessage.Text = " Email này đã được đăng ký xin vui lòng chọn Email khác.";
            return;
        }
        try
        {
            TblCustomers customer = new TblCustomers();
            customer.Email = txtEmail.Text;
            customer.FName = txtFName.Text;
            customer.LName = txtLName.Text;
            customer.Idlanguage = Convert.ToInt32(drLanguage.SelectedValue);
            customer.Pass = Encryption.EncryptToString(txtPassword.Text);
            customer.IsSupperAdmin = false;

            userDAO.Insert_Update(customer, 1);

            flag = true;

        }
        catch (Exception ex)
        {
            Session[Global.SESSION_ERROR] = ex;
            Response.Redirect("~/Error.aspx", true);
        }
        if (flag)
        {
             ScriptManager.RegisterStartupScript(Button1, Button1.GetType(), "ScriptLoginSuccess", "UpdateParentsLogin();", true);
        }
     
    }
}
